package com.ming.seatMonitoring.service.ServiceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ming.seatMonitoring.mapper.BookRoomMapper;
import com.ming.seatMonitoring.pojo.DO.BookRoomInfoDO;
import com.ming.seatMonitoring.pojo.DO.RoomInfoDO;
import com.ming.seatMonitoring.service.BookRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author 小明
 * @date 2021/10/22
 * @description
 */
@Service
public class BookRoomServiceImpl extends ServiceImpl<BookRoomMapper, BookRoomInfoDO> implements BookRoomService {

    @Autowired
    BookRoomMapper bookRoomMapper;

    @Override
    public boolean addBookInfo(BookRoomInfoDO bookInfo) {
        bookInfo.setCreateTime(new Date());
        final int insert = baseMapper.insert(bookInfo);
        return insert > 0;
    }

    @Override
    public boolean deleteBookInfo(int roomId) {
        QueryWrapper<BookRoomInfoDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("roomId",roomId);
        final BookRoomInfoDO bookRoomInfoDO = new BookRoomInfoDO();
        bookRoomInfoDO.setDeleteTime(new Date());
        final int update = baseMapper.update(bookRoomInfoDO, queryWrapper);
        return update > 0;
    }

    @Override
    public boolean updateBookInfo(BookRoomInfoDO bookInfo) {
        bookInfo.setUpdateTime(new Date());
        QueryWrapper<BookRoomInfoDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("roomId", bookInfo.getRoomId());
        return update(bookInfo,queryWrapper);
    }

    @Override
    public Page<BookRoomInfoDO> getBookInfo(Page<BookRoomInfoDO> page) {
        return bookRoomMapper.selectBookInfo(page);
    }

    @Override
    public BookRoomInfoDO searchBookInfo(int roomId) {
        return bookRoomMapper.searchBookInfo(roomId);
    }

}
